HDU 5750 Dertouzos
HDU_5750
描述
A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.
Peter has two positive integers n and d. He would like to know the number of integers below n whose maximum positive proper divisor is d.
输入格式
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains two integers n and d (2≤n,d≤109).
输出格式
For each test case, output an integer denoting the answer.
样例
输入
9
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13
输出
1
2
1
0
0
0
0
0
4
思路
数学证明如下:
若d为素数,k为整数,在所有d·k<=N的情况下,只有k为小于等于d的素数,才能保证d为最大因子。
若d为合数,令d=m·h,m为d的最小质因子,h=d/m;k为整数,则有 k·h·m<=N。当k为小于m的质数时,易证。
当k为小于m的合数或者k>m时,则不能保证d是最大因子。
证毕。
AC代码
|
|